/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

%module (docstring="Fulguro Measure Module") flgrmeasure

%include ../common/common.i

/*********************** Include for wrapper **********************/

%inline %{
#include <flgrCoreTypes.h>
#include <flgrCoreErrors.h>
#include <flgrCoreData.h>
#include <flgrCoreIO.h>
#include <flgrCoreVector.h>
#include <flgrMeasureBase.h>
#include "flgrmeasure_ext.h"
%}



/**********************************************************************************************
 **********************************************************************************************
 * FLGR_Data2D Functions exports
 **********************************************************************************************
 **********************************************************************************************/

/********************** Typemaps ***************************/


/*********************** Documentation ***********************/

%feature("autodoc","""
[in] data to measure (FLGR_Data1D)

optional:
[out] vector volume (FLGR_Vector)
or
[in] type of the volume (FLGR_Type)

[return] [vol_channel_0, vol_channel_n]\n
Get the volume (each data values are summed)
""") flgr1d_measure_volume_1;
%feature("autodoc"," ") flgr1d_measure_volume_2;
%feature("autodoc"," ") flgr1d_measure_volume;


%feature("autodoc","""
[in] data to measure (FLGR_Data1D)

optional:
[out] vector expected_value (FLGR_Vector)
or
[in] type of the expected_value (FLGR_Type)

[return] [vol_channel_0, vol_channel_n]\n
Get the expected value
""") flgr1d_measure_expected_value_1;
%feature("autodoc"," ") flgr1d_measure_expected_value_2;
%feature("autodoc"," ") flgr1d_measure_expected_value;




%feature("autodoc","""
[in] data to measure (FLGR_Data1D)

optional:
[out] vector min (FLGR_Vector)
[out] vector max (FLGR_Vector)

[return] [[min_channel_0,...,min_channel_n], [max_channel_0,...,max_channel_n]] \n
Get the min/max global
""") flgr1d_measure_min_max_1;
%feature("autodoc"," ") flgr1d_measure_min_max_2;
%feature("autodoc"," ") flgr1d_measure_min_max;






%feature("autodoc","""
[in] data to measure (FLGR_Data2D)

optional:
[out] vector volume (FLGR_Vector)
or
[in] type of the volume (FLGR_Type)

[return] [vol_channel_0, vol_channel_n]\n
Get the volume (each data values are summed)
""") flgr2d_measure_volume_1;
%feature("autodoc"," ") flgr2d_measure_volume_2;




%feature("autodoc","""
[in] data to measure (FLGR_Data2D)

optional:
[out] vector min (FLGR_Vector)
[out] vector max (FLGR_Vector)

[return] [[min_channel_0,...,min_channel_n], [max_channel_0,...,max_channel_n]] \n
Get the min/max global
""") flgr2d_measure_min_max_1;
%feature("autodoc"," ") flgr2d_measure_min_max_2;



%rename (flgr1d_measure_expected_value) flgr1d_measure_expected_value_1(FLGR_Data1D *, FLGR_Vector *);
%rename (flgr1d_measure_expected_value) flgr1d_measure_expected_value_2(FLGR_Data1D *, FLGR_Type = FLGR_UINT32);

%rename (flgr1d_measure_volume) flgr1d_measure_volume_1(FLGR_Data1D *, FLGR_Vector *);
%rename (flgr1d_measure_volume) flgr1d_measure_volume_2(FLGR_Data1D *, FLGR_Type = FLGR_UINT32);

%rename (flgr2d_measure_volume) flgr2d_measure_volume_1(FLGR_Data2D *, FLGR_Vector *);
%rename (flgr2d_measure_volume) flgr2d_measure_volume_2(FLGR_Data2D *, FLGR_Type = FLGR_UINT32);

%rename (flgr1d_measure_min_max) flgr1d_measure_min_max_1(FLGR_Data1D *, FLGR_Vector *, FLGR_Vector *);
%rename (flgr1d_measure_min_max) flgr1d_measure_min_max_2(FLGR_Data1D *);

%rename (flgr2d_measure_min_max) flgr2d_measure_min_max_1(FLGR_Data2D *, FLGR_Vector *, FLGR_Vector *);
%rename (flgr2d_measure_min_max) flgr2d_measure_min_max_2(FLGR_Data2D *);


%typemap(out) (FLGR_Vector **) {
  int k;
  int spp = $1[0]->spp;
  int type = $1[0]->type;
  SwigObject lmin;
  SwigObject lmax;
  FLGR_Vector *vmin = $1[0];
  FLGR_Vector *vmax = $1[1];

  $result = SwigCreateArray(2);
  lmin = SwigCreateArray(spp);
  lmax = SwigCreateArray(spp);

  SwigSetArrayVal($result,0,lmin);
  SwigSetArrayVal($result,1,lmax);

  switch(type) {
  case FLGR_BIT:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgBIT( (fgBIT*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgBIT( (fgBIT*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT8:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT8( (fgUINT8*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT8( (fgUINT8*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT16:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT16( (fgUINT16*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT16( (fgUINT16*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT32:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCUInt((unsigned int) flgr_get_array_fgUINT32( (fgUINT32*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCUInt((unsigned int) flgr_get_array_fgUINT32( (fgUINT32*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT64:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCULongLong((unsigned long long) flgr_get_array_fgUINT64( (fgUINT64*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCULongLong((unsigned long long) flgr_get_array_fgUINT64( (fgUINT64*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT8:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgINT8( (fgINT8*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgINT8( (fgINT8*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT16:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgINT16( (fgINT16*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgINT16( (fgINT16*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgINT32( (fgINT32*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgINT32( (fgINT32*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCLongLong((long long) flgr_get_array_fgINT64( (fgINT64*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCLongLong((long long) flgr_get_array_fgINT64( (fgINT64*)(vmax->array), k) ));
    }
    break;

  case FLGR_FLOAT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigFloat_FromCFloat((float) flgr_get_array_fgFLOAT32( (fgFLOAT32*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigFloat_FromCFloat((float) flgr_get_array_fgFLOAT32( (fgFLOAT32*)(vmax->array), k) ));
    }
    break;

  case FLGR_FLOAT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigFloat_FromCDouble((double) flgr_get_array_fgFLOAT64( (fgFLOAT64*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigFloat_FromCDouble((double) flgr_get_array_fgFLOAT64( (fgFLOAT64*)(vmax->array), k) ));
    }

  }

  if($1[0] != NULL)
    flgr_vector_destroy($1[0]);

  if($1[1] != NULL)
    flgr_vector_destroy($1[1]);

  flgr_free($1);
}


extern FLGR_Vector **flgr1d_measure_min_max_1(FLGR_Data1D *dat, FLGR_Vector *mini, FLGR_Vector *maxi);
extern FLGR_Vector **flgr2d_measure_min_max_1(FLGR_Data2D *dat, FLGR_Vector *mini, FLGR_Vector *maxi);
%clear  (FLGR_Vector **);








%typemap(out) (FLGR_Vector **) {
  int k;
  int spp = $1[0]->spp;
  int type = $1[0]->type;
  SwigObject lmin;
  SwigObject lmax;
  FLGR_Vector *vmin = $1[0];
  FLGR_Vector *vmax = $1[1];

  $result = SwigCreateArray(2);
  lmin = SwigCreateArray(spp);
  lmax = SwigCreateArray(spp);

  SwigSetArrayVal($result,0,lmin);
  SwigSetArrayVal($result,1,lmax);

  switch(type) {
  case FLGR_BIT:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgBIT( (fgBIT*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgBIT( (fgBIT*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT8:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT8( (fgUINT8*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT8( (fgUINT8*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT16:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT16( (fgUINT16*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgUINT16( (fgUINT16*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT32:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCUInt((unsigned int) flgr_get_array_fgUINT32( (fgUINT32*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCUInt((unsigned int) flgr_get_array_fgUINT32( (fgUINT32*)(vmax->array), k) ));
    }
    break;

  case FLGR_UINT64:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCULongLong((unsigned long long) flgr_get_array_fgUINT64( (fgUINT64*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCULongLong((unsigned long long) flgr_get_array_fgUINT64( (fgUINT64*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT8:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgINT8( (fgINT8*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgINT8( (fgINT8*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT16:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgINT16( (fgINT16*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgINT16( (fgINT16*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCInt((int) flgr_get_array_fgINT32( (fgINT32*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCInt((int) flgr_get_array_fgINT32( (fgINT32*)(vmax->array), k) ));
    }
    break;

  case FLGR_INT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigInt_FromCLongLong((long long) flgr_get_array_fgINT64( (fgINT64*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigInt_FromCLongLong((long long) flgr_get_array_fgINT64( (fgINT64*)(vmax->array), k) ));
    }
    break;

  case FLGR_FLOAT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigFloat_FromCFloat((float) flgr_get_array_fgFLOAT32( (fgFLOAT32*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigFloat_FromCFloat((float) flgr_get_array_fgFLOAT32( (fgFLOAT32*)(vmax->array), k) ));
    }
    break;

  case FLGR_FLOAT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal(lmin, k, SwigFloat_FromCDouble((double) flgr_get_array_fgFLOAT64( (fgFLOAT64*)(vmin->array), k) ));
      SwigSetArrayVal(lmax, k, SwigFloat_FromCDouble((double) flgr_get_array_fgFLOAT64( (fgFLOAT64*)(vmax->array), k) ));
    }

  }

  if($1[0] != NULL)
    flgr_vector_destroy($1[0]);

  if($1[1] != NULL)
    flgr_vector_destroy($1[1]);

  flgr_free($1);
}
extern FLGR_Vector **flgr1d_measure_min_max_2(FLGR_Data1D *dat);
extern FLGR_Vector **flgr2d_measure_min_max_2(FLGR_Data2D *dat);

%clear  (FLGR_Vector **);


















%typemap(out) (FLGR_Vector *) {
  int k;
  int spp = $1->spp;
  int type = $1->type;

  $result = SwigCreateArray(spp);

  switch(type) {
  case FLGR_UINT32:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCUInt((unsigned int) flgr_get_array_fgUINT32( (fgUINT32*)($1->array), k) ));
    }
    break;

  case FLGR_UINT64:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCULongLong((unsigned long long) flgr_get_array_fgUINT64( (fgUINT64*)($1->array), k) ));
    }
    break;

  case FLGR_INT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCInt((int) flgr_get_array_fgINT32( (fgINT32*)($1->array), k) ));
    }
    break;

  case FLGR_INT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCLongLong((long long) flgr_get_array_fgINT64( (fgINT64*)($1->array), k) ));
     }
    break;

  case FLGR_FLOAT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigFloat_FromCFloat((float) flgr_get_array_fgFLOAT32( (fgFLOAT32*)($1->array), k) ));
    }
    break;

  case FLGR_FLOAT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigFloat_FromCDouble((double) flgr_get_array_fgFLOAT64( (fgFLOAT64*)($1->array), k) ));
    }
    break;

  default:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigObjectEmpty);
    }
     
  }

}

extern FLGR_Vector *flgr1d_measure_volume_1(FLGR_Data1D *, FLGR_Vector *);
extern FLGR_Vector *flgr2d_measure_volume_1(FLGR_Data2D *, FLGR_Vector *);

extern FLGR_Vector *flgr1d_measure_expected_value_1(FLGR_Data1D *, FLGR_Vector *);


%clear  (FLGR_Vector *);















%typemap(out) (FLGR_Vector *) {
  int k;
  int spp = $1->spp;
  int type = $1->type;

  $result = SwigCreateArray(spp);

  switch(type) {
  case FLGR_UINT32:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCUInt((unsigned int) flgr_get_array_fgUINT32( (fgUINT32*)($1->array), k) ));
    }
    break;

  case FLGR_UINT64:
   for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCULongLong((unsigned long long) flgr_get_array_fgUINT64( (fgUINT64*)($1->array), k) ));
    }
    break;

  case FLGR_INT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCInt((int) flgr_get_array_fgINT32( (fgINT32*)($1->array), k) ));
    }
    break;

  case FLGR_INT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigInt_FromCLongLong((long long) flgr_get_array_fgINT64( (fgINT64*)($1->array), k) ));
     }
    break;

  case FLGR_FLOAT32:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigFloat_FromCFloat((float) flgr_get_array_fgFLOAT32( (fgFLOAT32*)($1->array), k) ));
    }
    break;

  case FLGR_FLOAT64:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigFloat_FromCDouble((double) flgr_get_array_fgFLOAT64( (fgFLOAT64*)($1->array), k) ));
    }
    break;

  default:
    for(k=0 ; k<spp ; k++) {
      SwigSetArrayVal($result, k, SwigObjectEmpty);
    }
     
  }

  if($1 != NULL)
    flgr_vector_destroy($1);
}

extern FLGR_Vector *flgr1d_measure_volume_2(FLGR_Data1D *dat, FLGR_Type type = FLGR_UINT32);
extern FLGR_Vector *flgr2d_measure_volume_2(FLGR_Data2D *dat, FLGR_Type type = FLGR_UINT32);

extern FLGR_Vector *flgr1d_measure_expected_value_2(FLGR_Data1D *dat, FLGR_Type type = FLGR_UINT32);
%clear  (FLGR_Vector *);





